﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Waf.Applications;
using System.Windows.Input;
using HighLandirect.Applications.Views;
using HighLandirect.Domain;
using System;
using System.Linq;

namespace HighLandirect.Applications.ViewModels
{
    public class OrderListViewModel : ViewModel<IOrderListView>
    {
        private readonly IEnumerable<Order> orders;
        private IEnumerable<OrderHistory> orderHistories;
        private readonly IEnumerable<Store> stores;
        private readonly IEnumerable<ReportMemo> reportMemos;
        private readonly ObservableCollection<Order> selectedOrders;
        private readonly ObservableCollection<OrderHistory> selectedOrderHistories;
        private Order selectedOrder;
        private OrderHistory selectedOrderHistory;
        private Store selectedStore;
        private ReportMemo selectedReportMemo;
        private ICommand printCommand;
        private ICommand removeCommand;
        private ICommand addNewCommand;
        private ICommand addOrderFromSelectedHistoryCommand;
        //private ICommand filterOrderHistoryCommand;
        private string sendCustomerId;
        private ICommand showOrderHistoryBySendCustomerCommand;

        public OrderListViewModel(IOrderListView view, IEnumerable<Order> orders,
                                                 IEnumerable<Store> stores,
                                                 IEnumerable<ReportMemo> reportMemos)
            : base(view)
        {
            if (orders == null) { throw new ArgumentNullException("orders"); }

            this.orders = orders;
            this.selectedOrders = new ObservableCollection<Order>();
            this.selectedOrderHistories = new ObservableCollection<OrderHistory>();

            this.stores = stores;
            this.reportMemos = reportMemos;

            this.selectedStore = this.stores.Where(x => x.IsDefault == true).FirstOrDefault();
            this.selectedReportMemo = this.reportMemos.Where(x => x.IsDefault == true).FirstOrDefault();
            this.sendCustomerId = "";
        }

        public IEnumerable<Order> Orders { get { return orders; } }
        public IEnumerable<OrderHistory> OrderHistories
        {
            get { return orderHistories; }
            set
            {
                if (orderHistories != value)
                {
                    orderHistories = value;
                    RaisePropertyChanged("OrderHistories");
                }
            }
        }

        public ObservableCollection<Order> SelectedOrders
        {
            get { return selectedOrders; }
        }

        public ObservableCollection<OrderHistory> SelectedOrderHistories
        {
            get { return selectedOrderHistories; }
        }

        public Order SelectedOrder
        {
            get { return selectedOrder; }
            set
            {
                if (selectedOrder != value)
                {
                    selectedOrder = value;
                    RaisePropertyChanged("SelectedOrder");
                }
            }
        }

        public string SendCustomerId
        {
            get { return sendCustomerId; }
            set
            {
                if (sendCustomerId != value)
                {
                    sendCustomerId = value;
                    RaisePropertyChanged("SendCustomerId");
                }
            }
        }

        public OrderHistory SelectedOrderHistory
        {
            get { return selectedOrderHistory; }
            set
            {
                if (selectedOrderHistory != value)
                {
                    selectedOrderHistory = value;
                    RaisePropertyChanged("SelectedOrderHistory");
                }
            }
        }

        public Store SelectedStore
        {
            get { return selectedStore; }
            set
            {
                if (selectedStore != value)
                {
                    selectedStore = value;
                    RaisePropertyChanged("SelectedStore");
                }
            }
        }

        public ReportMemo SelectedReportMemo
        {
            get { return selectedReportMemo; }
            set
            {
                if (selectedReportMemo != value)
                {
                    selectedReportMemo = value;
                    RaisePropertyChanged("SelectedReportMemo");
                }
            }
        }

        public ICommand PrintCommand
        {
            get { return printCommand; }
            set
            {
                if (printCommand != value)
                {
                    printCommand = value;
                    RaisePropertyChanged("PrintCommand");
                }
            }
        }

        public ICommand AddNewCommand
        {
            get { return addNewCommand; }
            set
            {
                if (addNewCommand != value)
                {
                    addNewCommand = value;
                    RaisePropertyChanged("AddNewCommand");
                }
            }
        }

        public ICommand RemoveCommand
        {
            get { return removeCommand; }
            set
            {
                if (removeCommand != value)
                {
                    removeCommand = value;
                    RaisePropertyChanged("RemoveCommand");
                }
            }
        }

        public ICommand AddOrderFromSelectedHistoryCommand
        {
            get { return addOrderFromSelectedHistoryCommand; }
            set
            {
                if (addOrderFromSelectedHistoryCommand != value)
                {
                    addOrderFromSelectedHistoryCommand = value;
                    RaisePropertyChanged("AddOrderFromSelectedHistoryCommand");
                }
            }
        }

        public ICommand ShowOrderHistoryBySendCustomerCommand
        {
            get { return showOrderHistoryBySendCustomerCommand; }
            set
            {
                if (showOrderHistoryBySendCustomerCommand != value)
                {
                    showOrderHistoryBySendCustomerCommand = value;
                    RaisePropertyChanged("ShowOrderHistoryBySendCustomerCommand");
                }
            }
        }

        //public ICommand FilterOrderHistoryCommand
        //{
        //    get { return filterOrderHistoryCommand; }
        //    set
        //    {
        //        if (filterOrderHistoryCommand != value)
        //        {
        //            filterOrderHistoryCommand = value;
        //            RaisePropertyChanged("FilterOrderHistoryCommand");
        //        }
        //    }
        //}
    }
}
